package com.yyh.BookLendSystem.biz;

import java.sql.SQLException;
import java.util.Map;


import com.yyh.BookLendSystem.dao.ReaderDao;

public class ReaderBiz {
	private ReaderDao dao = new ReaderDao();
	private static Map<String, Object> loginedUser;
	public  Map<String, Object> login (String name ,String pwd) throws BizException{
		//业务逻辑
		if(name==null||name.isEmpty()) {
			throw new BizException("用户名为空,请重新填写");
		}
		if(pwd==null||pwd.isEmpty()) {
			throw new BizException("密码为空,请输入密码");
		}
		try {
			Map<String, Object> reader = dao.selectForLogin(name, pwd);
			
			if(reader == null) {
				throw new BizException("用户名或密码错误");
			}
			
			//登录成功保存用户
			loginedUser = reader;
			
			return reader;
		} catch (SQLException e) {
		
			throw new BizException("业务异常请联系管理员");
		}
	}
	
	public static Map<String, Object> getLoginedUser(){
		return loginedUser;
	}
}
